# -*- coding:utf-8 -*-
"""
__author__='Wang Bo'
email:joker_wb@163.com
爬取内涵段子内容
"""

import requests

#请求的网址
# url='http://neihanshequ.com/joke/?is_json=1&app_name=neihanshequ_web&max_time=1519537265'
#请求网址，获取网页源代码,获得这个json文件

#requests.get(url)

#翻页
time_stamp=1514378948
while(type(time_stamp)==int or type(time_stamp)==float):
    url = 'http://neihanshequ.com/joke/?is_json=1&app_name=neihanshequ_web&max_time=' + str(time_stamp)
    html = requests.request('GET', url)
    html.encoding = 'utf-8'
    for i in range(20):
        content=html.json()['data']['data'][i]['group']['text']#提取段子
        #保存本地
        with open("neihanduanzi.txt",'a',encoding='utf-8') as f:
            f.write(content+'\n'*2)

    time_stamp=html.json()['data']['max_time']
    print(time_stamp)